package com.mapapp.flutter_mapapp.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mapapp.flutter_mapapp.R;
import com.mapapp.flutter_mapapp.bean.ProcessBean;

import java.util.List;

public class NewDataStepAdapter extends BaseQuickAdapter<ProcessBean, BaseViewHolder> {

    public NewDataStepAdapter(int layoutResId, @Nullable List<ProcessBean> data) {
        super(layoutResId, data);
    }

    private boolean showRadioBtn;
    private boolean isHistoryDetailStep;

    public void setShowRadioBtn(boolean showRadioBtn) {
        this.showRadioBtn = showRadioBtn;
        notifyDataSetChanged();
    }

    public void setHistoryDetailStep(boolean isHistoryDetailStep)
    {
        this.isHistoryDetailStep = isHistoryDetailStep;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ProcessBean item) {
        TextView tvStep = helper.getView(R.id.tv_step);
        TextView progressStep = helper.getView(R.id.progress_step);
        ImageView ivCheck = helper.getView(R.id.iv_check);
        helper.addOnClickListener(R.id.iv_check);

        tvStep.setText(item.getProcessName());
        switch (item.getState()) {
            case 1:  //完成
                progressStep.setText("已完成");
                ivCheck.setVisibility(showRadioBtn ? View.VISIBLE : View.GONE);
                ivCheck.setSelected(item.isSelected());
                break;
            case -1:  //未完成
                progressStep.setText("");
                break;
            case 2:   //进行中
                progressStep.setText("进行中");
                break;
        }

        int i = getData().indexOf(item);
        if(isHistoryDetailStep)
        {
            i=item.getProcessOrder();
        }
        if (item.getState() == 1 || item.getState() == 2) {
            switch (i) {
                case 0:
                    progressStep.setBackgroundResource(R.drawable.btn_new_data_step1);
                    break;
                case 1:
                    progressStep.setBackgroundResource(R.drawable.btn_new_data_step2);
                    break;
                case 2:
                    progressStep.setBackgroundResource(R.drawable.btn_new_data_step3);
                    break;
                case 3:
                    progressStep.setBackgroundResource(R.drawable.btn_new_data_step4);
                    break;
                case 4:
                    progressStep.setBackgroundResource(R.drawable.btn_new_data_step5);
                    break;
            }
        } else {
            progressStep.setBackgroundResource(R.drawable.btn_new_data_step_uncompleted);
        }


    }

}
